package main

import (
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"study_abroad_system_back_end/common"
	"study_abroad_system_back_end/dao"
	"study_abroad_system_back_end/models"
	"study_abroad_system_back_end/routers"
)

func main()  {
	cfg, err := common.ParseConfig("./config/app.json")
	if err != nil {
		panic(err.Error())
	}
	err = dao.InitMySQL(cfg)
	if err != nil {
		panic(err)
	}
	defer dao.DB.Close()
	dao.DB.AutoMigrate(&models.User{})
	dao.DB.AutoMigrate(&models.College{})
	dao.DB.AutoMigrate(&models.Major{})

	dao.InitRedis(cfg)
	
	r := routers.SetupRouter()
	r.Static("/school_pictures", "./school_pictures")
	r.Run(cfg.AppHost + ":" + cfg.AppPort)
	//r.Run("localhost:3001")
}